package model

import (
	"common/globals"
	"gorm.io/gorm"
)

type MealProduct struct {
	gorm.Model
	MealProductName  string  `gorm:"column:meal_product_name;type:varchar(50);not null" json:"meal_product_name"`
	MealProductPrice float64 `gorm:"column:meal_product_price;type:decimal(10,2);not null" json:"meal_product_price"`
	Image            string  `gorm:"column:image;type:varchar(255);not null" json:"image"`
	Socket           int     `gorm:"column:socket;type:int(11);not null" json:"socket"`
	Classification   string  `gorm:"column:classification;type:enum('精品推荐','人气热卖','精选套餐');not null" json:"classification"`
}

func (m *MealProduct) TableName() string {
	return "meal_product"
}
func (m *MealProduct) GetAllMealProductByClassification(Classification string) ([]MealProduct, error) {
	var mealProducts []MealProduct
	if Classification == "" {
		err := globals.Db.Find(&mealProducts).Error
		return mealProducts, err
	} else {
		err := globals.Db.Where("classification=?", Classification).Find(&mealProducts).Error
		return mealProducts, err
	}
}
func (m *MealProduct) GetMealProductInfoById(id int) error {
	return globals.Db.Where("id =?", id).Limit(1).Find(&m).Error
}
